package com.guchenbo.example.lock;

/**
 * Created by CreGu on 2016/6/21.
 */
public class Test3 {
    public static synchronized void write(){
        for (;;) {
            System.out.println("write");
        }
    }

    public static synchronized boolean read(){
        for (;;) {
            System.out.println("read");
        }
    }

    public static void main(String[] args) {
        final Test3 test1 = new Test3();
        final Test3 test2 = new Test3();
        Thread a = new Thread(new Runnable() {
            @Override
            public void run() {
                test1.write();
            }
        });
        Thread b = new Thread(new Runnable() {
            @Override
            public void run() {
                Test3.read();
            }
        });

        a.start();
        b.start();
    }
}
